package 链表.easy;

import 链表.middle.SanErBa;

import java.util.ArrayList;

/**
 * @author Lw中
 * @date 2020/9/24 15:53
 */
public class ErSanSi {

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    /**
     * 回文链表
     * @param head
     * @return
     */
    public boolean isPalindrome(ListNode head) {
        ArrayList<Integer> temp = new ArrayList<Integer>();
        ListNode node = head;
        while (node != null) {
            temp.add(node.val);
            node = node.next;
        }
        int i = temp.size()-1;
        node = head;
        while (node != null) {
            if (node.val != temp.get(i)) {
                return false;
            }
            i--;
            node = node.next;
        }
        return true;
    }

    public static void main(String[] args) {

    }

}
